﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace DMEditor
{
    public partial class frmCopy : Form
    {
        int srcKitID = 0;

        public frmCopy()
        {
            InitializeComponent();
        }

        private void frmCopy_Load(object sender, EventArgs e)
        {

        }

        private void btnCopy_Click(object sender, EventArgs e)
        {

            int destKitID = ddlCopyKits.SelectedIndex;

            DM10Kit srcKit = Program.settings.kits[srcKitID];
            DM10Kit destKit = Program.settings.kits[destKitID];

            for (int i = 0; i < 21; ++i)
            {
                for (int j = 0; j < 2; ++j)
                {
                    destKit.instruments[i].instLayers[j]._category = srcKit.instruments[i].instLayers[j]._category;
                    destKit.instruments[i].instLayers[j]._sound = srcKit.instruments[i].instLayers[j]._sound;

                    destKit.instruments[i].instLayers[j]._level = srcKit.instruments[i].instLayers[j]._level;
                    destKit.instruments[i].instLayers[j]._pan = srcKit.instruments[i].instLayers[j]._pan;
                    destKit.instruments[i].instLayers[j]._decay = srcKit.instruments[i].instLayers[j]._decay;
                    destKit.instruments[i].instLayers[j]._attack = srcKit.instruments[i].instLayers[j]._attack;

                    // FX
                    destKit.instruments[i].instLayers[j]._reverb = srcKit.instruments[i].instLayers[j]._reverb;
                    destKit.instruments[i].instLayers[j]._effects = srcKit.instruments[i].instLayers[j]._effects;
                    destKit.instruments[i].instLayers[j]._eq = srcKit.instruments[i].instLayers[j]._eq; 

                    // Tone
                    destKit.instruments[i].instLayers[j]._semitone = srcKit.instruments[i].instLayers[j]._semitone;
                    destKit.instruments[i].instLayers[j]._finetune = srcKit.instruments[i].instLayers[j]._finetune;
                    destKit.instruments[i].instLayers[j]._filter = srcKit.instruments[i].instLayers[j]._filter;
                    destKit.instruments[i].instLayers[j]._filtertype = srcKit.instruments[i].instLayers[j]._filtertype; 


                    // Dynamics
                    destKit.instruments[i].instLayers[j]._velDecay = srcKit.instruments[i].instLayers[j]._velDecay;
                    destKit.instruments[i].instLayers[j]._velFilter = srcKit.instruments[i].instLayers[j]._velFilter;
                    destKit.instruments[i].instLayers[j]._velLevel = srcKit.instruments[i].instLayers[j]._velLevel;
                    destKit.instruments[i].instLayers[j]._velPitch = srcKit.instruments[i].instLayers[j]._velPitch; 

                    // Other settings
                    destKit.instruments[i].instLayers[j]._output = srcKit.instruments[i].instLayers[j]._output;
                    destKit.instruments[i].instLayers[j]._priority = srcKit.instruments[i].instLayers[j]._priority;
                    destKit.instruments[i].instLayers[j]._muteGroup = srcKit.instruments[i].instLayers[j]._muteGroup;
                    destKit.instruments[i].instLayers[j]._monoPlayback = srcKit.instruments[i].instLayers[j]._monoPlayback; 

                }
            }

            destKit.name = srcKit.name;

            destKit.reverbType = srcKit.reverbType;
            destKit.reverbSize = srcKit.reverbSize;
            destKit.reverbColor = srcKit.reverbColor;
            destKit.reverbLevel = srcKit.reverbLevel;

            // FX settings
            destKit.fxType = srcKit.fxType;
            destKit.fxRate = srcKit.fxRate;
            destKit.fxDepth = srcKit.fxDepth;
            destKit.fxLevel = srcKit.fxLevel;
            destKit.fxDamp = srcKit.fxDamp;
            destKit.fxFeedbackL = srcKit.fxFeedbackL;
            destKit.fxFeedbackR = srcKit.fxFeedbackR;
            destKit.fxDelayL = srcKit.fxDelayL;
            destKit.fxDelayR = srcKit.fxDelayR;

            // Compression
            destKit.compType = srcKit.compType;
            destKit.compLevel = srcKit.compLevel;
            destKit.compOutLevel = srcKit.compOutLevel;

            // EQ settings
            destKit.eqLFGain = srcKit.eqLFGain;
            destKit.eqLFFreq = srcKit.eqLFFreq;
            destKit.eqHFGain = srcKit.eqHFGain;
            destKit.eqHFFreq = srcKit.eqHFFreq;

            // Set the current kit to the new one we just copied to
            Program.MainForm.stripKits.SelectedIndex = destKitID;

            // Reload the name on destKit
            Program.MainForm.stripKits.Items[destKitID] = (destKitID + 100) + " (" + destKit.name + ")";

            // Upload destkit to the module?
            if (chkSendToModule.Checked) Program.module.UploadKit(destKitID);

            Close();
        }

        private void btnCancel_Click(object sender, EventArgs e)
        {
            Close();
        }

        public void SetupForm()
        {
            srcKitID = Program.MainForm.stripKits.SelectedIndex;
            for (int i = 0; i < 100; ++i) ddlCopyKits.Items.Add(Program.MainForm.stripKits.Items[i]);

            lblCopyKit.Text = "Copy kit #" + (srcKitID + 100) + " over which kit?";

            ddlCopyKits.SelectedIndex = srcKitID;

            
        }
    }
}
